<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <ul>
        <li data-toggle-id="email-form"> Animals</li>
        <ul>
            <li hidden class="email-form" data-tog-id="email">
                Mammals
                <ul hidden id="email">
                    <li>Cow</li>
                    <li>Cow</li>
                    <li>Cow</li>
                </ul>
            </li>
            <li hidden class="email-form" data-tog-id="form">
                Other
                <ul hidden id="form">
                    <li>Birds</li>
                    <li>Birds</li>
                    <li>Birds</li>
                </ul>
            </li>
        </ul>
    </ul>
    <script>
        document.body.addEventListener('click', function(e) {
            var target = e.target;
            console.log(target);
            //   console.log(target);
            //   console.log(target.dataset.toggleId);
            //   var lis=document.getElementsByClassName(target.dataset.toggleId);
            //   console.log(lis);
            if (target.dataset.toggleId !== '') {
                var lis = document.getElementsByClassName(target.dataset.toggleId);
                //   if(lis){
                //       lis.hidden=!lis.hidden;
                //   }
                for (var i = 0; i < lis.length; i++) {
                    if (lis[i]) {
                        lis[i].hidden = !lis[i].hidden;
                    }
                }
            }
            if (target.dataset.togId !== '') {
                var uls1 = document.getElementById(target.dataset.togId);
                console.log(uls1);
                if (uls1) {
                    uls1.hidden = !uls1.hidden;
                }
            }
            // console.log(target.dataset.toggId !== '');
            // var uls2 = document.getElementById(target.dataset.toggId);
            // console.log(uls2);
            // if (target.dataset.toggId !== '') {
            //     var uls2 = document.getElementById(target.dataset.toggId);
            //     if (uls2) {
            //         uls2.hidden = !uls2.hidden;
            //     }
            // }
        })
    </script>
</body>

</html>